package com.tech.cloudapp.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.*;

/**
 * Created on 2019/7/5.
 *
 * @author qiubindbigold
 */
public class DateUtils {
    private static Logger logger = LoggerFactory.getLogger(DateUtils.class);

    public final static String DATEFORMAT = "yyyy-MM-dd";
    public final static String DATEFORMATCN = "yyyy年MM月dd日";
    public final static String DATETIME2FORMAT = "yyyy-MM-dd HH:mm";
    public final static String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss";
    public final static String DATEFORMAT2= "yyyy/MM";
	public final static String DATEFORMAT3 = "yyyyMMdd";

    static final long ONE_SECOND = 1000L;

	public static String getNowDateStr(long time, String format) {
		Date date = new Date(time);
		return new SimpleDateFormat(format).format(date);

	}

    /**
     * 将时间戳转为Int类型时间戳
     *
     * @param timeInMillis
     * @return
     */
    public static int toSecs(long timeInMillis) {
        return (int) Math.ceil((double) timeInMillis / ONE_SECOND);
    }

    /**
     * 将Int类型时间戳转为Long类型时间戳
     *
     * @param timeInSecs
     * @return
     */
    public static long toMillis(int timeInSecs) {
        return timeInSecs * ONE_SECOND;
    }

    /**
     * 获取当前时间
     *
     * @param format
     * @return
     */
    public static String getDate(String format) {
        DateFormat df = new SimpleDateFormat(format);
        return df.format(new Date());
    }

    /**
     * @return
     * @Description: 获取当前patten 格式的时间
     * @author wangjing
     * @date 2017年6月23日
     */
    public static Date getPattenDate(String patten) {
        Date date = new Date();
		// 注意：调用该方法时，若传入的patten不为null，则if的注释需去掉
//        if (null == patten || "".equals(patten)) {
//            patten = "yyyy-MM-dd HH:mm";
//        }
        SimpleDateFormat format = new SimpleDateFormat(patten);
        try {
            return format.parse(format.format(date));
        } catch (ParseException e) {
            return date;
        }
    }


    public static Date parseDate(String dateStr) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
        try {
            return format.parse(dateStr);
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date parseDate1(String dateStr) {
        SimpleDateFormat format = new SimpleDateFormat(DATEFORMAT);
        try {
            return format.parse(dateStr);
        } catch (ParseException e) {
            return null;
        }
    }


    /**
     * @return
     * @Description: 获取当前时间 yyyyMMdd 格式
     * @author wangjing
     * @date 2017年6月3日
     */
    public static String getNowDateStr() {
        Date date = new Date();
        return new SimpleDateFormat("yyyyMMdd").format(date);

    }


    /**
     * 日期转字符串
     *
     * @param date
     * @return
     */
    public static String date2String(Date date) {
        if (date == null) {
            return null;
        }
        return new SimpleDateFormat("yyyy-MM-dd").format(date);
    }


    /**
     * @param date
     * @param format
     * @return
     * @Description: 时间转换为字符串
     * @author 王静
     * @date 2017年4月28日
     */
    public static String date2String(Date date, String format) {
        if (date == null) {
            return null;
        }
        if (format == null || "".equals(format)) {
            format = DATEFORMAT;
        }
        return new SimpleDateFormat(format).format(date);
    }

    /**
     * 时间戳long 转为 yyyy-MM-dd HH:mm:ss 字符串
     */
    public static String long2StringDate(Long time) {
        if (time != null) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return format.format(time);
        }
        return null;
    }


    /**
     * 时间戳long 转为 yyyy-MM-dd HH:mm 字符串
     */
    public static String long3StringDate(Long time) {
        if (time != null) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            return format.format(time);
        }
        return null;
    }

    public static String long4StringDate(Long time) {
        if (time != null) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            return format.format(time);
        }
        return null;
    }

    /**
     * 时间戳long 转为 yyyy-MM-dd字符串
     */
    public static String long2StrDate(Long time) {
        if (time != null) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            return format.format(time);
        } else {
            return null;
        }
    }

    public static Date string2date(String dateStr) {
        return string2date(dateStr, null);
    }

    public static Date string2date(String dateStr, String format) {
        if (format == null || "".equals(format)) {
            format = DATEFORMAT;
        }
        Date date = null;
        if (dateStr != null && !"".equals(dateStr)) {
            DateFormat df = new SimpleDateFormat(format);
            try {
                date = df.parse(dateStr);
            } catch (Exception e) {
                logger.error("日期转换失败", e);
            }
        }
        return date;
    }

    //----------------------------------------------------------------------------------------------------------------------------------------------
    public static Date getSystemDate() {
        return new Date();
    }

    public static java.sql.Date getSystemSqlDate() {
        return new java.sql.Date(new Date().getTime());
    }

    /**
     * 获取当年的第一天
     *
     * @return
     */
    public static Date getCurrYearFirst() {
        Calendar currCal = Calendar.getInstance();
        int currentYear = currCal.get(Calendar.YEAR);
        return getYearFirst(currentYear);
    }

    /**
     * 获取当年的最后一天
     *
     * @return
     */
    public static Date getCurrYearLast() {
        Calendar currCal = Calendar.getInstance();
        int currentYear = currCal.get(Calendar.YEAR);
        return getYearLast(currentYear);
    }

    /**
     * 获取某年第一天日期
     *
     * @param year 年份
     * @return Date
     */
    public static Date getYearFirst(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
        Date currYearFirst = calendar.getTime();
        return currYearFirst;
    }

    /**
     * 获取某年最后一天日期
     *
     * @param year 年份
     * @return Date
     */
    public static Date getYearLast(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
        calendar.roll(Calendar.DAY_OF_YEAR, -1);
        Date currYearLast = calendar.getTime();

        return currYearLast;
    }

    /**
     * 将一个日期字符串转化成日期(按相应的格式)
     *
     * @param date
     * @param format 格式
     * @return Date或null
     */
    public static Date stringToDate(String date, String format) {
        if (StringUtils.isEmpty(format)) {
            format = "yyyy-MM-dd";
        }
        Date newDate = null;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            if (date != null && !date.equals("")) {
                newDate = sdf.parse(date);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return newDate;
    }

    /**
     * 将一个日期转化成日期字符串(按相应的格式)
     *
     * @param date
     * @param format 格式
     * @return 日期字符串或""
     */
    public static String dateToString(Date date, String format) {
        if (StringUtils.isEmpty(format)) {
            format = "yyyy-MM-dd";
        }
        String newDate = "";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            if (date != null) {
                newDate = sdf.format(date);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return newDate;
    }

    /**
     * 取得系统当前时间
     *
     * @return String yyyy-MM-dd
     */
    public static String getCurrentDate() {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);
        String month = swith(rightNow.get(Calendar.MONTH) + 1);
        int day = rightNow.get(Calendar.DATE);
        return year + "-" + month + "-" + swith(day);
    }

    /**
     * 取得系统当前时间
     *
     * @return String yyyy年mm月dd日
     */
    public static String getCurrentDate1() {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);
        String month = swith(rightNow.get(Calendar.MONTH) + 1);
        int day = rightNow.get(Calendar.DATE);
        return year + "年" + month + "月" + swith(day) + "日";
    }

    /**
     * 取得系统当前时间
     *
     * @return String yyyymmdd
     */
    public static String getCurrentDate2() {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);
        String month = swith(rightNow.get(Calendar.MONTH) + 1);
        int day = rightNow.get(Calendar.DATE);
        return year + "" + month + "" + swith(day);
    }

    /**
     * 取得系统当前时间
     *
     * @return String yyyy-MM
     */
    public static String getCurrentDate3() {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);
        String month = swith(rightNow.get(Calendar.MONTH) + 1);
        return year + "-" + month;
    }

    /**
     * 取得系统当前时间
     *
     * @return String yyyyMMddhhmmss
     */
    public static String getCurrentDate4() {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.SECOND, 0);

        return "" + c.get(Calendar.YEAR) + "" + swith((c.get(Calendar.MONTH) + 1))
                + "" + swith(c.get(Calendar.DATE)) + "" + c.get(Calendar.HOUR_OF_DAY)
                + "" + c.get(Calendar.MINUTE) + "" + c.get(Calendar.SECOND);
    }

    /**
     * 取得系统当前时间
     *
     * @return String yyyy-MM-dd HH:mm:ss
     */
    public static String getCurrentDate5() {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.SECOND, 0);
        return "" + c.get(Calendar.YEAR) + "-"
                + swith((c.get(Calendar.MONTH) + 1)) + "-"
                + swith(c.get(Calendar.DATE)) + " "
                + swith(c.get(Calendar.HOUR_OF_DAY)) + ":"
                + swith(c.get(Calendar.MINUTE)) + ":"
                + swith(c.get(Calendar.SECOND));
    }

    /**
     * 取得系统当前时间 常用于订单号
     *
     * @return String yyyyMMddhhmmss
     */
    public static String getCurrentDate6() {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.SECOND, 0);
        String year = c.get(Calendar.YEAR) + "";
        return "" + year.subSequence(2, year.length()) + ""
                + swith((c.get(Calendar.MONTH) + 1)) + "" + swith(c.get(Calendar.DATE)) + "-"
                + c.get(Calendar.HOUR_OF_DAY) + "" + c.get(Calendar.MINUTE)
                + "" + c.get(Calendar.SECOND) + "-"
                + c.get(Calendar.MILLISECOND);
    }

    /**
     * @return String yyyyMMddhhmmssSSS
     * @author ambuf_guanshen 取得系统当前时间
     */
    public static String getCurrentDate7() {
        Calendar rightNow = Calendar.getInstance();
        int YY = rightNow.get(Calendar.YEAR);
        String MM = swith(rightNow.get(Calendar.MONTH) + 1);
        int DD = rightNow.get(Calendar.DATE);
        int HH = rightNow.get(Calendar.HOUR_OF_DAY);
        int mm = rightNow.get(Calendar.MINUTE);
        int SS = rightNow.get(Calendar.SECOND);
        int MI = rightNow.get(Calendar.MILLISECOND);
        return YY + "" + MM + "" + swith(DD) + "" + HH + "" + mm + "" + SS + "" + MI;
    }

    private static String swith(int i) {
        String result = "";
        if ((i > 0) && (i < 10)) {
            result = "0" + Integer.toString(i);
        } else {
            result = Integer.toString(i);
        }
        return result;
    }

    /**
     * 取得系统当前时间前n年的相对应的一天
     *
     * @param n int
     * @return date
     */
    public static Date getNYearBeforeCurrentDay(int n) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.YEAR, -n);
        return c.getTime();
    }

    /**
     * 取得系统当前时间前n个月的相对应的一天
     *
     * @param n int
     * @return String yyyy-MM-dd
     */
    public static String getNMonthBeforeCurrentDay(int n) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -n);
        return "" + c.get(Calendar.YEAR) + "-" + swith((c.get(Calendar.MONTH) + 1))
                + "-" + swith(c.get(Calendar.DATE));
    }

    /**
     * 取得系统当前时间后n个月的相对应的一天
     *
     * @param n int
     * @return String yyyy-MM-dd
     */
    public static String getNMonthAfterCurrentDay(int n) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, n);
        return "" + c.get(Calendar.YEAR) + "-" + swith((c.get(Calendar.MONTH) + 1))
                + "-" + swith(c.get(Calendar.DATE));
    }

    /**
     * 取得系统当前时间前n天
     *
     * @param n int
     * @return String yyyy-MM-dd
     */
    public static String getNDayBeforeCurrentDate(int n) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE));
    }

    /**
     * 取得系统当前时间后n天
     *
     * @param n int
     * @return String yyyy-MM-dd
     */
    public static String getNDayAfterCurrentDate(int n) {
        Calendar c = Calendar.getInstance();
        c.add(c.DAY_OF_MONTH, n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE));
    }

    /**
     * 取得系统当前时间后n天
     *
     * @param n int
     * @return String yyyy-MM-dd
     */
    public static String getNDayAfterDate(LocalDate localDate,int n) {
        return localDate.plusDays(n).toString();
    }

    // ---------------------------------------------------------------------
    // 取过去一个时间对应的系统当年的一天
    public static String getCurrentDateAfterPastDate(String sPastDate) {
        if (sPastDate != null && !sPastDate.equals("")) {
            Date date = switchStringToDate(sPastDate);
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            int iPastYear = c.get(c.YEAR);
            Calendar c1 = Calendar.getInstance();
            int iCurrentYear = c1.get(c1.YEAR);
            c.add(c.YEAR, iCurrentYear - iPastYear);
            return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                    + swith(c.get(c.DATE));
        } else {
            return null;
        }
    }

    /**
     * 将一个日期字符串转化成日期
     *
     * @param sDate String
     * @return Date yyyy-MM-dd
     */
    public static Date switchStringToDate(String sDate) {
        Date date = null;
        if (sDate != null) {
            try {
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                date = df.parse(sDate);
            } catch (Exception e) {
                logger.info("日期转换失败:", e);
                //System.out.println("日期转换失败:" + e.getMessage());
            }
        }
        return date;
    }

    public static Date switchStringToDate(String sDate, String type) {
        Date date = null;
        if (sDate != null) {
            type = type == null ? DATEFORMAT : DATETIME2FORMAT;
            try {
                SimpleDateFormat df = new SimpleDateFormat(type);
                date = df.parse(sDate);
            } catch (Exception e) {
                logger.info("日期转换失败:", e);
                //System.out.println("日期转换失败:" + e.getMessage());
            }
        }
        return date;
    }

    /**
     * 将一个日期字符串转化成日期
     *
     * @param sDate String
     * @return Date yyyy-MM-dd HH:mm:ss
     */
    public static Date switchStringToDate2(String sDate) {
        Date date = null;
        if (sDate != null) {
            try {
                SimpleDateFormat df = new SimpleDateFormat(
                        "yyyy-MM-dd HH:mm:ss");
                date = df.parse(sDate);
            } catch (Exception e) {
                logger.info("日期转换失败:", e);
                //System.out.println("日期转换失败:" + e.getMessage());
            }
        }
        return date;
    }

    /**
     * 将一个日期转化成日期字符串
     *
     * @param date
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String switchDateToString(Date date) {
        String mydate = "";
        if (date != null) {
            try {
                SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                mydate = sp.format(date);
            } catch (Exception e) {
                logger.info("日期转换失败:", e);
                //System.out.println("日期转换失败:" + e.getMessage());
            }
        }
        return mydate;
    }

    /**
     * 将一个日期转化成日期字符串
     *
     * @param date
     * @return string yyyy-MM-dd
     */
    public static String switchDateToString2(Date date) {
        String mydate = "";
        if (date != null) {
            try {
                SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
                mydate = sp.format(date);
            } catch (Exception e) {
                logger.info("日期转换失败:", e);
                //System.out.println("日期转换失败:" + e.getMessage());
            }
        }
        return mydate;
    }

    /**
     * 输入两个字符串型的日期，比较两者的大小
     *
     * @param fromDate String
     * @param toDate   String
     * @return boolean before为true
     */
    public boolean compareTwoDateBigOrSmall(String fromDate, String toDate) {
        Date dateFrom = switchStringToDate(fromDate);
        Date dateTo = switchStringToDate(toDate);
        if (dateFrom != null && dateTo != null && dateFrom.before(dateTo)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 将一个日期字符串转化成Calendar
     *
     * @param sDate String
     * @return Calendar
     */
    public static Calendar switchStringToCalendar(String sDate) {
        Date date = switchStringToDate(sDate);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }

    public static Calendar switchStringToCalendar(String sDate, String type) {
        Date date = switchStringToDate(sDate, type);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }

    /**
     * 将一个日期转化成Calendar
     *
     * @param date Date
     * @return Calendar
     */
    public static Calendar switchStringToCalendar(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }

    public static String string2Date(String dateString) throws Exception {
        SimpleDateFormat newk = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
        SimpleDateFormat old = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d = newk.parse(dateString);
        return old.format(d);
    }

    /**
     * 取得某个时间前n个月的相对应的一天
     *
     * @param sDate String
     * @param n     int
     * @return String yyyy-MM-dd
     */
    public static String getNMonthBeforeOneDay(String sDate, int n) {
        Calendar c = switchStringToCalendar(sDate);
        c.add(c.MONTH, -n);
        return "" + c.get(c.YEAR) + "-" + (c.get(c.MONTH) + 1) + "-" + c.get(c.DATE);
    }

    /**
     * 取得系统当前时间时间前n个小时的相对应的时间
     *
     * @param n int
     * @return String yyyy-MM-dd HH:mm:ss
     */
    public static String getNHourBeforeOneDate(int n) {
        Calendar c = Calendar.getInstance();
        c.add(c.HOUR_OF_DAY, -n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE)) + " " + swith(c.get(c.HOUR_OF_DAY))
                + ":" + swith(c.get(c.MINUTE)) + ":" + swith(c.get(c.SECOND));
    }

    public static String getNHourAfterOneDateYYYYMMddHHmm(String sDate, int n) {
        Calendar c = switchStringToCalendar(sDate);
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date date = df.parse(sDate);
            c.setTime(date);
        } catch (Exception e) {
            logger.error("时间获取失败", e);
        }
        c.add(c.HOUR_OF_DAY, n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE)) + " " + swith(c.get(c.HOUR_OF_DAY))
                + ":" + swith(c.get(c.MINUTE));
    }

    public static String getNHourAfterOneDate(String sDate, int n) {
        Calendar c = switchStringToCalendar(sDate);
        c.add(c.HOUR_OF_DAY, n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE)) + " " + swith(c.get(c.HOUR_OF_DAY))
                + ":" + swith(c.get(c.MINUTE)) + ":" + swith(c.get(c.SECOND));
    }

    public static String getNMinuteAfterOneDate(String sDate, int n) {
        Calendar c = switchStringToCalendar(sDate);
        c.add(c.MINUTE, n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE)) + " " + swith(c.get(c.HOUR_OF_DAY))
                + ":" + swith(c.get(c.MINUTE)) + ":" + swith(c.get(c.SECOND));
    }

    public static String getNMinuteAfterOneDate(String sDate, int n, String dataType) {
        Calendar c = switchStringToCalendar(sDate, dataType);
        c.add(c.MINUTE, n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE)) + " " + swith(c.get(c.HOUR_OF_DAY))
                + ":" + swith(c.get(c.MINUTE)) + ":" + swith(c.get(c.SECOND));
    }

    /**
     * 取得系统当前时间后n个小时的相对应的时间
     *
     * @param n int
     * @return String yyyy-MM-dd HH:mm
     */
    public static String getNHourAfterOneDate(int n) {
        Calendar c = Calendar.getInstance();
        c.add(c.HOUR_OF_DAY, n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE)) + " " + swith(c.get(c.HOUR_OF_DAY))
                + ":" + swith(c.get(c.MINUTE));
        //+ ":" + swith(c.get(c.SECOND));
    }

    // 取得某个时间后n个月的相对应的一天
    public static String getNMonthAfterOneDay(String sDate, int n) {
        Calendar c = switchStringToCalendar(sDate);
        c.add(c.MONTH, n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE));
    }

    // 取得某个时间前n天,格式为yyyy-MM-dd
    public String getNDayBeforeOneDate(String sDate, int n) {
        Calendar c = switchStringToCalendar(sDate);
        c.add(c.DAY_OF_MONTH, -n);
        int m = c.get(c.MONTH) + 1;
        int d = c.get(c.DATE);
        return "" + c.get(c.YEAR) + (m < 10 ? "-0" : "-") + m
                + (d < 10 ? "-0" : "-") + d;
    }

    // 取得某个时间后n天,格式为yyyy-MM-dd
    public static String getNDayAfterOneDate(String sDate, int n) {
        Calendar c = switchStringToCalendar(sDate);
        c.add(c.DAY_OF_MONTH, n);
        int m = c.get(c.MONTH) + 1;
        int d = c.get(c.DATE);
        return "" + c.get(c.YEAR) + (m < 10 ? "-0" : "-") + m
                + (d < 10 ? "-0" : "-") + d;
    }

    // 判断系统当前时间是不是润年
    public static boolean isRunNian() {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(rightNow.YEAR);
        if (0 == year % 4 && (year % 100 != 0 || year % 400 == 0)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * method 将字符串类型的日期转换为一个timestamp（时间戳记java.sql.Timestamp）
     *
     * @param dateString 需要转换为timestamp的字符串
     * @return dataTime timestamp
     */
    public final static java.sql.Timestamp string2Time(String dateString) throws ParseException {
        DateFormat dateFormat;
        dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.SSS",
                Locale.ENGLISH);// 设定格式
        dateFormat.setLenient(false);
        Date timeDate = dateFormat.parse(dateString);// util类型
        java.sql.Timestamp dateTime = new java.sql.Timestamp(timeDate.getTime());// Timestamp类型,timeDate.getTime()返回一个long型
        return dateTime;
    }

    /**
     * method 将字符串类型的日期转换为一个Date（java.sql.Date）
     *
     * @param dateString 需要转换为Date的字符串
     * @return dataTime Date
     */
    public final static java.sql.Date string2SqlDate(String dateString) throws Exception {
        DateFormat dateFormat;
        dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
        dateFormat.setLenient(false);
        Date timeDate = dateFormat.parse(dateString);// util类型
        java.sql.Date dateTime = new java.sql.Date(timeDate.getTime());// sql类型
        return dateTime;
    }

    /**
     * utilDate转化成sqlDate
     *
     * @param utilDate
     * @return
     */
    public static java.sql.Date getSqlDate(Date utilDate) {
        java.sql.Date sqlDate = null;
        if (utilDate != null) {
            sqlDate = new java.sql.Date(utilDate.getTime());
        }
        return sqlDate;
    }

    /**
     * 毫秒转换成字符串型时间
     *
     * @param longDate
     * @return
     */
    public static String longToDate(long longDate) {
        long h = longDate / (1000 * 60 * 60);
        long m = (longDate - h * (1000 * 60 * 60)) / (1000 * 60);
        long s = (longDate - h * (1000 * 60 * 60) - m * (1000 * 60)) / (1000);
        return h + "时" + m + "分" + s + "秒";
    }

    public static String longToDateYear(long longDate) {
        Date dat = new Date(longDate);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dat);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(gc.getTime());
    }

    /**
     * 根据传入的Date对象和格式，返回格式化后的日期字符串
     *
     * @param date
     * @param strFormat
     * @return
     */
    public static String getFormatDate(Date date, String strFormat) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(strFormat);
        return simpleDateFormat.format(date);
    }

    /**
     * 返回两个日期间隔的分钟数
     *
     * @param startCal Calendar
     * @param endCal   Calendar
     * @return int
     */
    public static long getCalendarDiff(Calendar startCal, Calendar endCal) {
        long lResult = (startCal.getTimeInMillis() - endCal.getTimeInMillis()) / 1000 / 60;
        return lResult;
    }

    public static boolean isLeapYear(int year) {
        return 0 == year % 4 && (year % 100 != 0 || year % 400 == 0);
    }

    /**
     * 获得某年某月的天数
     *
     * @param year
     * @param month
     * @return
     */
    public static int getYearMonthDays(int year, int month) {
        int days = 0;
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 2:
                days = (0 == year % 4 && (year % 100 != 0 || year % 400 == 0)) ? 29 : 28;
                break;
            default:
                days = 30;
                break;
        }
        return days;
    }

    /**
     * 根据当前日期获得上周的日期区间（上周周一和周日日期）
     *
     * @return
     */
    public static String getLastTimeInterval() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        int dayOfWeek = calendar1.get(Calendar.DAY_OF_WEEK) - 1;
        int offset1 = 1 - dayOfWeek;
        int offset2 = 7 - dayOfWeek;
        calendar1.add(Calendar.DATE, offset1 - 7);
        calendar2.add(Calendar.DATE, offset2 - 7);
        String lastBeginDate = sdf.format(calendar1.getTime());
        String lastEndDate = sdf.format(calendar2.getTime());
        return lastBeginDate + "," + lastEndDate;
    }

    /**
     * 获取某个时间的一周开始时间
     *
     * @return
     */
    public static String getWeekBegin(Date date) {
        Calendar c = Calendar.getInstance();
        if (date != null) {
            c.setTime(date);
        }
        int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == 1) {
            dayOfWeek = 8;
        }
        c.add(Calendar.DAY_OF_MONTH, -(dayOfWeek - 2));
        return switchDateToString2(c.getTime());
    }

    /**
     * 获取本周的开始时间
     *
     * @return
     */
    public static String getWeekBegin() {
        return getWeekBegin(null);
    }

    /**
     * 获取本周的结束时间
     *
     * @return
     */
    public static String getWeekEnd() {
        return getWeekEnd(null);
    }

    /**
     * 获取本周的结束时间
     *
     * @return
     */
    public static String getWeekEnd(Date date) {
        Calendar c = Calendar.getInstance();
        // 注意：调用该方法时，若传入的date不为null，则if的注释需去掉
//        if (date != null) {
//            c.setTime(date);
//        }
        int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == 1) {
            dayOfWeek = 8;
        }
        c.add(Calendar.DAY_OF_MONTH, -(dayOfWeek - 2) + 6);
        return switchDateToString2(c.getTime());
    }

    /**
     * 添加年
     *
     * @param time 时间
     * @param year 年数
     * @return
     */
    public static Date addYear(Date time, Integer year) {
        //取得日期time中年的部分timeYear
        String timeStr = switchDateToString2(time);
        String timeYear = timeStr.substring(0, timeStr.indexOf("-"));
        //将timeYear转为Integer类型并加year
        Integer yearInte = Integer.parseInt(timeYear);
        timeYear = (yearInte + year) + "";
        //拼接加year后的日期转成日期类型并返回
        timeStr = timeYear + timeStr.substring(timeStr.indexOf("-"));
        return switchStringToDate(timeStr);
    }

    public static String addYear(String time) {
    	String timeYear = time.substring(0,time.indexOf("-"));
		Integer yearInte = Integer.parseInt(timeYear);
		timeYear = (yearInte + 5) + "";
		time = timeYear+time.substring(time.indexOf("-"));
		return time;
	}
    /**
     * 得到一年的开始时间
     */
    public static Date yearInitial(Date time) {
        //取得日期time中年的部分timeYear
        String timeStr = switchDateToString2(time);
        String timeYear = timeStr.substring(0, timeStr.indexOf("-"));
        //拼接加year后的日期转成日期类型并返回
        timeStr = timeYear + "-01-01";
        return switchStringToDate(timeStr);
    }

    /**
     * 添加月
     */
    public static Date monthAdd(Date time, Integer m) {
        Calendar c = Calendar.getInstance();
        c.setTime(time);
        c.add(Calendar.MONTH, m);
        return c.getTime();
    }

    /**
     * 获取某月的最后一天
     *
     * @author 张旭磊
     */
    public static String getLastDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR, year);
        //设置月份
        cal.set(Calendar.MONTH, month - 1);
        //获取某月最大天数
        int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String lastDayOfMonth = sdf.format(cal.getTime());

        return lastDayOfMonth;
    }

    /**
     * 两个日期相差周数
     */
    public static Integer twoDateDeffDay(Date maxTime, Date minTime) {
        return (int) (((maxTime.getTime() - minTime.getTime()) / ( 24 * 3600 * 1000)) + 1);
    }

    /**
     * 两个日期相差周数
     */
    public static Integer twoDateDeffWeek(Date maxTime, Date minTime) {
        return (int) (((maxTime.getTime() - minTime.getTime()) / (7 * 24 * 3600 * 1000)) + 1);
    }

    /**
     * 两个日期相差半月数
     */
    public static Integer twoDateDeffMot(Date maxTime, Date minTime) {
        if (maxTime == null || minTime == null) {
            return null;
        }
        Calendar maxCal = Calendar.getInstance();
        maxCal.setTime(maxTime);
        Integer aYear = maxCal.get(Calendar.YEAR);
        Integer aMonth = maxCal.get(Calendar.MONTH);
        Integer maxDay = maxCal.get(Calendar.DAY_OF_MONTH);
        Calendar minCal = Calendar.getInstance();
        minCal.setTime(minTime);
        Integer minYear = minCal.get(Calendar.YEAR);
        Integer minMonth = minCal.get(Calendar.MONTH);
        Integer minDay = minCal.get(Calendar.DAY_OF_MONTH);
        Integer absMonth = (aYear - minYear) * 12 + aMonth - minMonth;
        absMonth = absMonth * 2;
        if (maxTime.after(minTime)) {
            if (maxDay < minDay) {
                absMonth = absMonth - 2;
                maxDay = maxDay + 30;
            }
//			日期相差大于22天（30的四分之三）按一个月计算
            if ((maxDay - minDay + 1) > 30 * 3 / 4) {
                absMonth = absMonth + 2;
            } else
//			日期相差大于7天（30的四分之一）按半个月计算
                if ((maxDay - minDay + 1) > 30 * 1 / 4) {
                    absMonth = absMonth + 1;
                }
        }
        return absMonth;
    }

    /**
     * 取得当前年
     *
     * @return
     */
    public static Integer getCurrentYear() {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);
        return year;
    }

    /**
     * 取得当前月
     *
     * @return
     */
    public static Integer getCurrentMonth() {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.MONTH);
        return year;
    }

    /**
     * 取得当前日
     *
     * @return
     */
    public static Integer getCurrentDay() {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.DATE);
        return year;
    }

    /**
     * 获得两个日期之前相差的月份
     *
     * @param start
     * @param end
     * @return
     */
    public static int getMonthFromTwoDate(Date start, Date end) {
        if (start.after(end)) {
            Date t = start;
            start = end;
            end = t;
        }
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(start);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(end);
        Calendar temp = Calendar.getInstance();
        temp.setTime(end);
        temp.add(Calendar.DATE, 1);

        int year = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
        int month = endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);

        if ((startCalendar.get(Calendar.DATE) == 1) && (temp.get(Calendar.DATE) == 1)) {
            return year * 12 + month + 1;
        } else if ((startCalendar.get(Calendar.DATE) != 1) && (temp.get(Calendar.DATE) == 1)) {
            return year * 12 + month;
        } else if ((startCalendar.get(Calendar.DATE) == 1) && (temp.get(Calendar.DATE) != 1)) {
            return year * 12 + month;
        } else {
            return (year * 12 + month - 1) < 0 ? 0 : (year * 12 + month);
        }
    }

    /**
     * 获得两个日期之前相差的月份的日期列表
     * (返回的Date格式的日期中，只有年份和月份是有效值，日、时、分、秒都是虚拟值)
     *
     * @param startTime
     * @param endTime
     * @return
     * @throws Exception
     */
    public static List<Date> getDateListFromTwoDate(String startTime, String endTime) throws Exception {
        SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat ym = new SimpleDateFormat("yyyy-MM");
        Calendar startDate = Calendar.getInstance();
        Calendar endDate = Calendar.getInstance();

        startDate.setTime(ymd.parse(startTime));
        endDate.setTime(ymd.parse(endTime));
        String endYm = ym.format(endDate.getTime());

        List<Date> listDate = new ArrayList<Date>();
        while (true) {
            String strYm = ym.format(startDate.getTime());
            listDate.add(startDate.getTime());
            if (strYm.equals(endYm)) {
                break;
            }
            startDate.add(Calendar.MONTH, 1);
        }
        return listDate;
    }

    /**
     * 返回昨天的日期
     *
     * @param dateFormat 返回日期的格式
     * @return
     * @throws Exception
     */
    public static String getYesterday(String dateFormat) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);
        String yesterday = new SimpleDateFormat(dateFormat).format(cal.getTime());
        return yesterday;
    }

    /**
     * 比较两个时间相差多少天，多少个月，多少年
     *
     * @param stype 返回值类型   0为多少天，1为多少个月，2为多少年
     * @return 举例：
     * compareDate("2009-09-12", null, 0);//比较天
     * compareDate("2009-09-12", null, 1);//比较月
     * compareDate("2009-09-12", null, 2);//比较年
     */
    public static int compareDate(String startDay, String endDay, int stype) {
        int n = 0;
        //String[] u = {"天","月","年"};
        String formatStyle = stype == 1 ? "yyyy-MM" : "yyyy-MM-dd";

        endDay = endDay == null ? getCurrentDate() : endDay;

        DateFormat df = new SimpleDateFormat(formatStyle);
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        try {
            c1.setTime(df.parse(startDay));
            c2.setTime(df.parse(endDay));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        while (!c1.after(c2)) {                   // 循环对比，直到相等，n 就是所要的结果
            n++;
            if (stype == 1) {
                c1.add(Calendar.MONTH, 1);          // 比较月份，月份+1
            } else {
                c1.add(Calendar.DATE, 1);           // 比较天数，日期+1
            }
        }
        n = n - 1;
        if (stype == 2) {
            n = n / 365;
        }
        //System.out.println(startDay+" -- "+endDay+" 相差多少"+u[stype]+":"+n);
        return n;
    }

    /**
     * 取得系统当前时间前n天
     *
     * @param n int
     * @return String yyyy-MM-dd
     */
    public static String getNDayBeforeCurrentDate(Date date, int n) {
        Calendar c = Calendar.getInstance();
        if (date != null) {
            c.setTime(date);
        }
        c.add(Calendar.DAY_OF_MONTH, -n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE));
    }

    /**
     * 取得系统当前时间后n天
     *
     * @param n int
     * @return String yyyy-MM-dd
     */
    public static String getNDayAfterCurrentDate(Date date, int n) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(c.DAY_OF_MONTH, n);
        return "" + c.get(c.YEAR) + "-" + swith((c.get(c.MONTH) + 1)) + "-"
                + swith(c.get(c.DATE));
    }

    public static List<String> getWeekListDate(Date date) {
        List<String> listDate = new ArrayList<String>();
        String dateTime = getWeekBegin(date);
        listDate.add(dateTime);
        for (int i = 0; i < 6; i++) {
            Date switchStringToDate = switchStringToDate(dateTime);
            dateTime = getNDayAfterCurrentDate(switchStringToDate, 1);
            listDate.add(dateTime);
        }
        return listDate;
    }

    /**
     * 日期转字符串
     *
     * @param date
     * @return
     */
    public static String date2HourStr(Date date) {
        if (date == null) {
            return null;
        }
        return new SimpleDateFormat("HH:mm:ss").format(date);
    }

    public static String date2HourMi(Date date) {
        if (date == null) {
            return null;
        }
        return new SimpleDateFormat("HH:mm").format(date);
    }

    public static Map<String, String> printfWeeks(String date) throws Exception {
        Map<String, String> dataMap = new LinkedHashMap<String, String>();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        Date date1 = dateFormat.parse(date);
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date1);
        int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        int count = 0;
        for (int i = 1; i <= days; i++) {
            DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
            Date date2 = dateFormat1.parse(date + "-" + i);
            calendar.clear();
            calendar.setTime(date2);
            int k = calendar.get(Calendar.DAY_OF_WEEK);
            String key = "";
            if (k == 1) {// 若当天是周日
                count++;
                key = "第" + count + "周";
//                System.out.println("-----------------------------------");
//                System.out.println(key);
                String timeData = dataMap.get(key);
                if (StringUtils.isEmpty(timeData)) {
                    timeData = "";
                }
                if (i - 6 <= 1) {
//                    System.out.println("本周开始日期:" + date + "-" + 1);
                    timeData += date + "-" + 1 + ",";
                } else {
//                    System.out.println("本周开始日期:" + date + "-" + (i - 6));
                    timeData += date + "-" + (i - 6) + ",";
                }
//                System.out.println("本周结束日期:" + date + "-" + i);
                timeData += date + "-" + i;
//                System.out.println("-----------------------------------");
                dataMap.put(key, timeData);
            }
            if (k != 1 && i == days) {// 若是本月最后一天，且不是周日
                count++;
                key = "第" + count + "周";
//                System.out.println("-----------------------------------");
//                System.out.println(key);
//                System.out.println("本周开始日期:" + date + "-" + (i - k + 2));
//                System.out.println("本周结束日期:" + date + "-" + i);
                String timeData = date + "-" + (i - k + 2) + "," + date + "-" + i;
                dataMap.put(key, timeData);
//                System.out.println("-----------------------------------");
            }
        }
        return dataMap;
    }

    /**
     * 计算两个日期相隔的列表
     *
     * @param minDate
     * @param maxDate
     * @return
     * @throws ParseException
     */
    public static List<String> getDayBetween(String minDate, String maxDate) throws ParseException {
        ArrayList<String> result = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月

        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();

        min.setTime(sdf.parse(minDate));
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), min.get(min.DAY_OF_MONTH));

        max.setTime(sdf.parse(maxDate));
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), max.get(max.DAY_OF_MONTH));

        Calendar curr = min;
        while (curr.before(max) || curr.compareTo(max) == 0) {
            result.add(sdf.format(curr.getTime()));
            curr.add(Calendar.DAY_OF_MONTH, 1);
        }

        return result;
    }

    public static List<String> getDayBetweenList(String minDate, String maxDate) {

        ArrayList<String> result = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        try {
            min.setTime(sdf.parse(minDate));
            min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), min.get(min.DAY_OF_MONTH));
            max.setTime(sdf.parse(maxDate));
            max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), max.get(max.DAY_OF_MONTH));
            Calendar curr = min;
            while (curr.before(max) || curr.compareTo(max) == 0) {
                result.add(sdf.format(curr.getTime()));
                curr.add(Calendar.DAY_OF_MONTH, 1);
            }

        } catch (ParseException e) {
            // TODO Auto-generated catch block
			logger.error("日期处理异常",e);
        }

        return result;
    }


    /**
     * @return date
     * @author ambuf_guanshen 获取某年某月的开始时间
     */
    public static Date getBeginTime(String dateStr) {
        Date date = null;
        if (dateStr != null && !"".equals(dateStr)) {
            YearMonth yearMonth = YearMonth.of(getCurrentYearByString(dateStr), getCurrentMonthByString(dateStr) + 1);
            LocalDate localDate = yearMonth.atDay(1);
            LocalDateTime startOfDay = localDate.atStartOfDay();
            ZonedDateTime zonedDateTime = startOfDay.atZone(ZoneId.of("Asia/Shanghai"));
            date = Date.from(zonedDateTime.toInstant());
        }
        return date;
    }

    /**
     * @return date
     * @author ambuf_guanshen 获取某年某月的结束时间
     */
    public static Date getEndTime(String dateStr) {
        Date date = null;
        if (dateStr != null && !"".equals(dateStr)) {
            YearMonth yearMonth = YearMonth.of(getCurrentYearByString(dateStr), getCurrentMonthByString(dateStr) + 1);
            LocalDate endOfMonth = yearMonth.atEndOfMonth();
            LocalDateTime localDateTime = endOfMonth.atTime(23, 59, 59, 999);
            ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
            date = Date.from(zonedDateTime.toInstant());
        }
        return date;
    }

    /**
     * @param date String格式"yyyy-MM"
     * @return
     * @author ambuf_guanshen 获取年分
     */
    public static Integer getCurrentYearByString(String date) {
        Calendar c = Calendar.getInstance();
        c.setTime(string2date(date, "yyyy-MM"));
        int year = c.get(Calendar.YEAR);
        return year;
    }

    /**
     * @param date String格式"yyyy-MM"
     * @return
     * @author ambuf_guanshen 获取月分
     */
    public static Integer getCurrentMonthByString(String date) {
        Calendar c = Calendar.getInstance();
        c.setTime(string2date(date, "yyyy-MM"));
        int month = c.get(Calendar.MONTH);
        return month;
    }

    /**
     * @param date String格式"yyyy-MM"
     * @return
     * @author ambuf_guanshen 获取月分
     */
    public static Integer getCurrentDayByString(String date) {
        Calendar c = Calendar.getInstance();
        c.setTime(string2date(date, "yyyy-MM-dd"));
        int day = c.get(Calendar.DAY_OF_MONTH);
        return day;
    }

    public static List<String> createDate() throws ParseException {
        List<String> dateList = new ArrayList<String>();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        dateList.add(sf.format(c.getTime()));
        for (int i = 1; i <= 4; i++) {
            c.add(Calendar.DAY_OF_MONTH, 1);
            dateList.add(sf.format(c.getTime()));
        }
        return dateList;
    }


    /**
     * 功能描述：获取传入日期是周几
     *
     * @param date
     * @return
     * @author 关燊
     * @date 2017年2月17日
     */
    public static Integer getWeekOfDate(Date date) {
        int[] weekDays = {7, 1, 2, 3, 4, 5, 6};
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }

    /**
     * 计算指定日期之后N天的日期列表
     *
     * @param minDate
     * @param num
     * @return
     * @throws ParseException
     */
    public static List<String> getDayAfter(String minDate, Integer num) throws ParseException {
        ArrayList<String> result = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月

        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();

        min.setTime(sdf.parse(minDate));
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), min.get(min.DAY_OF_MONTH));

        max.add(Calendar.DATE, num);
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), max.get(max.DAY_OF_MONTH));

        Calendar curr = min;
        while (curr.before(max) || curr.compareTo(max) == 0) {
            result.add(sdf.format(curr.getTime()));
            curr.add(Calendar.DAY_OF_MONTH, 1);
        }

        return result;
    }

    /**
     * @return
     * @Description: 获取当前时间上一月日期
     * @author wangjing
     * @date 2018年3月15日
     */
    public static String getLastMonthDay() {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.MONTH, -1);
        Date m = c.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String mon = format.format(m);
        return mon;
    }

}
